package com.tangyuan.video.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tangyuan.aspect.AutoLog;
import com.tangyuan.common.result.Result;
import com.tangyuan.common.result.ResultCodeEnum;
import com.tangyuan.model.TyFinance;
import com.tangyuan.video.service.ITyFinanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @Description: ty_finance
 * @Author: jeecg-boot
 * @Date: 2024-03-24
 * @Version: V1.0
 */
@Api(tags = "ty_finance")
@RestController
@RequestMapping("/video/tyFinance")
@Slf4j
public class TyFinanceController {
    @Autowired
    private ITyFinanceService tyFinanceService;

    /**
     * 分页列表查询
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "ty_finance-分页列表查询", notes = "ty_finance-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<TyFinance>> queryPageList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return tyFinanceService.queryPageList(pageNo,pageSize);
    }

    /**
     * 添加
     *
     * @param tyFinance
     * @return
     */
    @AutoLog(value = "ty_finance-添加")
    @ApiOperation(value = "ty_finance-添加", notes = "ty_finance-添加")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody TyFinance tyFinance) {
        tyFinanceService.save(tyFinance);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑
     *
     * @param tyFinance
     * @return
     */
    @AutoLog(value = "ty_finance-编辑")
    @ApiOperation(value = "ty_finance-编辑", notes = "ty_finance-编辑")
    //@RequiresPermissions("video:ty_finance:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody TyFinance tyFinance) {
        tyFinanceService.updateById(tyFinance);
        return Result.ok("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "ty_finance-通过id删除")
    @ApiOperation(value = "ty_finance-通过id删除", notes = "ty_finance-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        tyFinanceService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "ty_finance-批量删除")
    @ApiOperation(value = "ty_finance-批量删除", notes = "ty_finance-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.tyFinanceService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "ty_finance-通过id查询", notes = "ty_finance-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<TyFinance> queryById(@RequestParam(name = "id", required = true) String id) {
        return tyFinanceService.queryById(id);
    }

}
